//
//  LJCPlayerView.m
//  WZLProduct
//
//  Created by 陆静聪 on 16/3/22.
//  Copyright © 2016年 HaiTeng. All rights reserved.
//

#import "LJCPlayerView.h"

@implementation LJCPlayerView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createPlay];
    }
    return self;
}

- (void)createPlay {
    _playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_playButton];
    [_playButton mas_makeConstraints:^(MASConstraintMaker *make) {
      make.bottom.top.mas_equalTo(0);
      make.centerX.equalTo(self.mas_centerX);
      make.width.mas_equalTo(50);
    }];
    
    [_playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    _nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_nextButton];
    [_nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_playButton.mas_centerY);
        make.left.equalTo(_playButton.mas_right).offset(50);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    [_nextButton setImage:[UIImage imageNamed:@"iconfont-jiantouyou.png"] forState:UIControlStateNormal];
    [_nextButton addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _priorButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_priorButton];
    [_priorButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_playButton.mas_centerY);
        make.right.equalTo(_playButton.mas_left).offset(-50);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    [_priorButton setImage:[UIImage imageNamed:@"iconfont-iconfonti2-copy-copy-copy-copy.png"] forState:UIControlStateNormal];
    
    [_priorButton addTarget:self action:@selector(priorAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _morebutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_morebutton];
    [_morebutton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_playButton.mas_centerY);
        make.left.equalTo(_nextButton.mas_right).offset(15);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    [_morebutton setImage:[UIImage imageNamed:@"iconfont-weibiaoti1.png"] forState:UIControlStateNormal];
    [_morebutton addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)moreAction:(UIButton *)more {
    _moreBlock();
}

- (void)priorAction:(UIButton *)prior {
    _priorBlock();
}

- (void)nextAction:(UIButton *)next {
    _nextBlock();
}
/** 播放开关 */
- (void)playAction:(UIButton *)play {
    [self playOnOrOff];
    [[LJCMusicPlay shareMusicPlayer] onOrOff];
    _discBlock();
    
}

- (void)playOnOrOff {
    if ([LJCMusicPlay shareMusicPlayer].isPlay == YES) {
        [_playButton setImage:[UIImage imageNamed:@"iconfont-zanting.png"] forState:UIControlStateNormal];
    } else {
        [_playButton setImage:[UIImage imageNamed:@"iconfont-iconfontbofang.png"] forState:UIControlStateNormal];
    }
}

@end
